package com.huichaoliu.adapters;

import java.util.ArrayList;
import java.util.List;

import com.huichaoliu.app.R;
import com.huichaoliu.data.UtilInfo;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class FragmentShowPicRightAdapter extends BaseAdapter {
	List<UtilInfo> list;
	Context context;
	LayoutInflater inflater;

	public FragmentShowPicRightAdapter(List<UtilInfo> list, Context context) {
		if (list == null) {
			list = new ArrayList<UtilInfo>();
		}
		this.list = list;
		this.context = context;
		this.inflater = LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return list.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	@SuppressWarnings("deprecation")
	@Override
	public View getView(int arg0, View arg1, ViewGroup arg2) {
		if (arg1 == null || arg1.getTag() == null) {
			arg1 = inflater.inflate(R.layout.show_pic_user_item, arg2, false);
			mHolder = new Holder();
			mHolder.content = (TextView) arg1
					.findViewById(R.id.showpic_content);
			mHolder.img = (ImageView) arg1.findViewById(R.id.showpic_img);
			mHolder.comment = (TextView) arg1
					.findViewById(R.id.showpic_comment);
			mHolder.diamon = (TextView) arg1.findViewById(R.id.showpic_diamon);
			arg1.setTag(mHolder);

		} else {
			mHolder = (Holder) arg1.getTag();
		}
		final UtilInfo info = list.get(arg0);
		mHolder.content.setText("哈哈哈哈哈哈哈哈哈哈哈哈哈7哈和哈哈4哈哈哈哈哈哈哈和和哈123哈哈23哈哈哈哈哈哈和");
		mHolder.img.setBackgroundDrawable(context.getResources().getDrawable(
				R.drawable.ic_avatar));
		mHolder.diamon.setText(info.getDiamonCount());
		mHolder.comment.setText(info.getCommentCount());

		return arg1;
	}

	Holder mHolder;

	public class Holder {
		ImageView img;
		TextView content;
		TextView comment;
		TextView diamon;
	}
}
